home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 41
/
Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso
/
-readerstuff-
/
steve_glover
/
source-code
/
cyberblanker.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-04-21
|
10KB
|
399 lines
/***********************************************************************
* *
* COPYRIGHTS *
* *
* Copyright (c) 1997 Zinneberg-Soft All Rights Reserved. *
* *
***********************************************************************/
#include "app.h"
#include "local.h"
#define SCREENWUNSH "PUBSCREEN"
#define DEF_SCREEN "Workbench"
#define DPMS_TOOL "DPMS"
#define DEFAULT_DPMS_SETTING "OFF"
#define FONT_NAME "FONTNAME"
#define DEFAULT_FONTNAME "topaz.font"
#define FONTS_SIZE "FONTSIZE"
#define DEFAULT_FONTSIZE "8"
#define WINDOW_X "WINDOWX"
#define DEFAULT_WINDOW_X 134
#define WINDOW_Y "WINDOWY"
#define DEFAULT_WINDOW_Y 64
#define SCREEN_WANTED_WIDTH 1480L
#define SCREEN_WANTED_HEIGHT 7240L
#define SCREEN_WANTED_DEPTH 24L
#define SCREEN_MIN_DEPTH 8L
#define BLANK 1L
#define UNBLANK 2L
ULONG NextDepth(ULONG );
ULONG DisplayID,Depth;
ULONG timeout = 0L;
ULONG blanked = 0L;
ULONG seconds = 10L;
ULONG Windowx = 134;
ULONG Windowy = 120;
ULONG SET_DPMS_GADGET = 5L;
LONG BlankerCommand;
char *fontname;
char *fontsize;
extern struct Custom custom;
extern struct TextAttr *mydesiredfont;
struct Screen *cybscreenasked;
struct Screen *CyberScreen = NULL;
struct Gadget *secgad;
struct Gadget *dpms_cyclegad;
UBYTE start_on_publicscreen[MAXPUBSCREENNAME];
int DPMS_WANTED = NULL;
/*****************************************/
VOID BlankerAction(struct CxMsg *cxm,CxObj *co);
VOID Blank(VOID);
VOID UnBlank(VOID);
VOID mysetupCustomGadgets(struct Gadget **gad);
BOOL setupBlanker(VOID)
{
char *dpms_tool_type;
char *screen_tool_type;
CxObj *objectlist;
seconds = ArgInt( ttypes, "SECONDS", 60 );
screen_tool_type = ArgString( ttypes,SCREENWUNSH,DEF_SCREEN);
strcpy(start_on_publicscreen, screen_tool_type);
fontname = ArgString( ttypes,FONT_NAME,DEFAULT_FONTNAME);
fontsize = ArgString( ttypes,FONTS_SIZE,DEFAULT_FONTSIZE);
Windowx = ArgInt( ttypes,WINDOW_X,DEFAULT_WINDOW_X);
Windowy = ArgInt( ttypes,WINDOW_Y,DEFAULT_WINDOW_Y);
/**************************/
dpms_tool_type = ArgString( ttypes,DPMS_TOOL,DEFAULT_DPMS_SETTING);
if(strcmpi(dpms_tool_type,"OFF")==0)
{
SSET_DPMS_OFF();
}
if(strcmpi(dpms_tool_type,"H")==0)
{
SSET_DPMS_STANDBY();
}
if(strcmpi(dpms_tool_type,"V")==0)
{
SSET_DPMS_SUSPEND();
}
/********************************************************/
objectlist=CxCustom( BlankerAction, 0L);
if (CxObjError(objectlist))
{
D( printf("nocapslock: filter error %lx\n", CxObjError(objectlist) ) );
DeleteCxObjAll(objectlist);
return(0);
}
AttachCxObj(broker, objectlist);
return(TRUE);
}
VOID BlankerAction(struct CxMsg *cxm,CxObj *co)
{
register struct InputEvent *ie;
/* D( kprintf("BlankerAction\n") ); */
/* I KNOW that all messages getting this far are CXM_IEVENT */
ie = (struct InputEvent *) CxMsgData((CxMsg *)cxm);
if(ie->ie_Class==IECLASS_TIMER)
{
/* D( printf("IECLASS_TIMER\n"); ) */
if(! blanked)
{
/*D( printf("blanked=0x%lx Bump timeout=%ld\n",blanked,timeout);)*/
if(++timeout >= ((ULONG)(seconds*10L)))
{
D( printf("########Blank Screen\n"); )
/* Blank(); */
BlankerCommand=BLANK;
Signal(maintask,csigflag);
blanked=TRUE;
}
}
} else {
if(ie->ie_Class!=IECLASS_TIMER)
{
D( printf("########UnBlank\n"); )
/* UnBlank(); */
BlankerCommand=UNBLANK;
Signal(maintask,csigflag);
timeout=0L;
blanked=FALSE;
}
}
}
VOID Blank(VOID)
{
/* Let CyberGraphX search a display mode for us! */
Depth=SCREEN_WANTED_DEPTH;
while (Depth)
{
if ((DisplayID=BestCModeIDTags(CYBRBIDTG_NominalWidth, SCREEN_WANTED_WIDTH,
CYBRBIDTG_NominalHeight,SCREEN_WANTED_HEIGHT,
CYBRBIDTG_Depth,Depth,
TAG_DONE))!=INVALID_ID)
{
/* Because older version of the "cybergraphics.library" don't handle */
/* CYBRBIDTG_Depth properly we query the real depth of the mode. */
Depth=GetCyberIDAttr(CYBRIDATTR_DEPTH,DisplayID);
break;
}
/* retry with less bits per pixel */
Depth=NextDepth(Depth);
}
if (Depth<SCREEN_MIN_DEPTH)
{
ErrorF ("Can't find a CyberGraphics ScreenMode!");
terminate();
}
/* open screen, but let Intuition choose the actual dimensions */
if ((CyberScreen=OpenScreenTags(NULL,
SA_DisplayID,DisplayID,
SA_Depth,Depth,
TAG_DONE))==NULL)
{
ErrorF ("Can't find a Suitable CyberGraphics ScreenMode!");
terminate();
}
CVideoCtrlTags (&CyberScreen->ViewPort,SETVC_DPMSLevel,DPMS_WANTED,TAG_DONE);
}
VOID UnBlank(VOID)
{
if(CyberScreen)
{
CVideoCtrlTags (&CyberScreen->ViewPort,SETVC_DPMSLevel,DPMS_ON,TAG_DONE);
CloseScreen(CyberScreen);
CyberScreen=NULL;
}
}
STRPTR DPMSLabels[] =
{
"H",
"V",
"H/V",
NULL,
};
VOID mysetupCustomGadgets(struct Gadget **gad)
{
struct NewGadget ng;
ng.ng_VisualInfo=vi;
ng.ng_TopEdge = topborder+32;
ng.ng_LeftEdge = 110;
ng.ng_Width = 60;
ng.ng_Height = 20;
ng.ng_GadgetText = " ";
ng.ng_TextAttr = mydesiredfont;
ng.ng_GadgetID = GAD_CYCLE;
ng.ng_Flags = NG_HIGHLABEL;
ng.ng_VisualInfo = vi;
dpms_cyclegad = *gad = CreateGadget(CYCLE_KIND, *gad, &ng,
GTCY_Labels, DPMSLabels,
GTCY_Active, SET_DPMS_GADGET,
TAG_DONE);
ng.ng_TopEdge = topborder+32;
ng.ng_LeftEdge = 10;
ng.ng_Width = 40;
ng.ng_Height = 20;
ng.ng_GadgetText = "Hide";
ng.ng_TextAttr = mydesiredfont;
ng.ng_GadgetID = GAD_HIDE;
ng.ng_Flags = NULL;
ng.ng_VisualInfo = vi;
*gad = CreateGadget(BUTTON_KIND,*gad, &ng,TAG_DONE);
ng.ng_TopEdge = topborder+32;
ng.ng_LeftEdge = 60;
ng.ng_Width = 40;
ng.ng_Height = 20;
ng.ng_GadgetText = "Quit";
ng.ng_TextAttr = mydesiredfont;
ng.ng_GadgetID = GAD_DIE;
ng.ng_Flags = NULL;
ng.ng_VisualInfo = vi;
*gad = CreateGadget(BUTTON_KIND,*gad, &ng,TAG_DONE);
ng.ng_TopEdge = topborder+5;
ng.ng_LeftEdge = 100;
ng.ng_Width = 60;
ng.ng_Height = 22;
ng.ng_GadgetText = "Seconds";
ng.ng_TextAttr = mydesiredfont;
ng.ng_GadgetID = GAD_SECS;
ng.ng_Flags = NULL;
ng.ng_VisualInfo = vi;
secgad = *gad = CreateGadget(INTEGER_KIND,*gad, &ng,GTIN_Number,seconds,GTIN_MaxChars,4,STRINGA_Justification,STRINGRIGHT,TAG_DONE);
}
VOID myHandleGadget(ULONG gad,ULONG code)
{
/* D( kprintf("custom: HandleGadget(%lx)\n",gad); ) */
switch(gad)
{
/****************************************************************/
case GAD_CYCLE:
{ while (code == 0)
{
DPMS_WANTED = DPMS_STANDBY;
break;
}
while (code == 1)
{
DPMS_WANTED = DPMS_SUSPEND;
break;
}
while (code == 2)
{
DPMS_WANTED = DPMS_OFF;
break;
}
}
default: break;
case GAD_HIDE:
/* D( kprintf("custom: HandleGadget() GAD_HIDE\n"); ) */
shutdownWindow();
break;
case GAD_DIE:
/* D( kprintf("custom: HandleGadget() GAD_DIE\n"); ) */
terminate();
case GAD_SECS:
/* D( kprintf("custom: HandleGadget() GAD_SECS\n"); ) */
seconds=((struct StringInfo *)secgad->SpecialInfo)->LongInt;
}
}
VOID MyHandleCustomSignal(VOID)
{
/* D( kprintf("custom: MyHandleCustomSignal() enter\n"); ) */
if(BlankerCommand==BLANK)
Blank();
else
if(BlankerCommand==UNBLANK)
UnBlank();
}
ULONG NextDepth(ULONG Depth)
{
switch (Depth)
{
case 24L: /* 24Bit not available? Try 16Bit! */
return 16L;
case 16L: /* 15Bit not available? Try 15Bit! */
return 15L;
default: /* Not even 15Bit available? Forget it! */
return 0L;
}
}
VOID SHOWABOUT()
{
EasyRequest(window,
&aboutcybereasy,NULL);
}
VOID SHOWCONFIG()
{
EasyRequest(window,
&progconfig,NULL);
}
/*******************************************/
void ErrorF(char *Format,...)
{
void *Data;
Data= &Format+1L;
if (((struct Process *)FindTask(NULL))->pr_CLI)
{
(void)VPrintf(Format,Data);
(void)FPutC(Output(),'\n');
(void)Flush(Output());
}
else
{
struct EasyStruct EasyStruct;
ULONG IDCMPFlags;
EasyStruct.es_StructSize=sizeof(struct EasyStruct);
EasyStruct.es_Flags=0L;
EasyStruct.es_Title="CyberBlanker FatalError";
EasyStruct.es_TextFormat=Format;
EasyStruct.es_GadgetFormat="Ok";
IDCMPFlags=0L;
(void)EasyRequestArgs(NULL,&EasyStruct,&IDCMPFlags,Data);
}
}
/***************************************************/
VOID SSET_DPMS_STANDBY()
{
SET_DPMS_GADGET = 0;
DPMS_WANTED = DPMS_STANDBY;
GT_SetGadgetAttrs(dpms_cyclegad, window, NULL,
GTCY_Active, SET_DPMS_GADGET, TAG_DONE);
}
VOID SSET_DPMS_OFF()
{
SET_DPMS_GADGET = 2;
DPMS_WANTED = DPMS_OFF;
GT_SetGadgetAttrs(dpms_cyclegad, window, NULL,
GTCY_Active, SET_DPMS_GADGET, TAG_DONE);
}
VOID SSET_DPMS_SUSPEND()
{
SET_DPMS_GADGET = 1;
DPMS_WANTED = DPMS_SUSPEND;
GT_SetGadgetAttrs(dpms_cyclegad, window, NULL,
GTCY_Active, SET_DPMS_GADGET, TAG_DONE);
}
/*
VOID SAVECONFIG()
{
}
*/